<template>
	<view class="container">
		<!-- <view class="tab_box">
			<u-tabs :list="list" :is-scroll="false" :current="current" @change="change" active-color="#EA3D37"
				bar-height="6" bar-width="40"></u-tabs>
		</view> -->
		<view class="nolist" v-if="orderList.length==0">
			<view style="text-align: center;">
				<view>
				</view>
				<view style="color: #666;">暂无相关订单</view>
			</view>
		</view>
		<view class="list" v-for="(item,index) in orderList" :key="index" @click="gourls(item)" v-else>
			<view class="title">
				<view class="order_num">订单号：{{item.order_id}}</view>
				<view class="status">{{item._status._title}}</view>
			</view>
			<view class="content_con">
				<view class="small_info" v-for="(item2,index2) in item.cartInfo" :key="index2">
					<image :src="item2.productInfo.image" mode="aspectFill"></image>
					<view class="infos">
						<view class="name">{{item2.productInfo.store_name}}</view>
						<view class="sku">{{item2.productInfo.attrInfo.suk}}</view>
						<view class="num_a_wd">
							<view>x{{item2.cart_num}}</view>
							<view class="wd_box" v-if="item2.bd_value !== ''">
								<text class="ice" style="margin-right: 10rpx;">冰冻{{item2.bdInfo.bd}}</text>|
								<text style="margin-left: 10rpx;">常温{{item2.bdInfo.cw}}</text>
							</view>
						</view>
					</view>
					<view class="price_box">
						<view>
							<view class="big_price"><text>￥</text>{{item2.productInfo.price}}</view>
							<view class="small_price"><text>￥</text>{{item2.productInfo.ot_price}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="btns">
				<view class="count_box">
					<view class="money">
						实付金额：<text>￥{{item.total_price}}</text>
					</view>
					<view class="goods">共{{item.total_num}}件商品</view>
				</view>
				<view class="btn_box">
					<view class="btn success" @click.stop="applyClick(item)">
						申请售后</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					name: '可申请'
				}, {
					name: '已申请'
				}],
				orderList: [],
				current: 0,
				count: 1,
				page: 1,
				pageSize: 15,
				status: 'loadmore',
			}
		},
		onLoad() {
			this.getData()
		},
		onReachBottom() {
			if (this.orderList.length < this.pageSize || this.status == 'nomore') return;
			this.status = 'loading';
			this.page++
			this.getData()
		},
		methods: {
			applyClick(item) {
				this.$gourl(
					`/mallPage/afterSales/applySales?orderInfo=${JSON.stringify(item)}`
				)
			},
			getData() {
				uni.showLoading({
					title: '加载中'
				})
				this.$allApi.getOrderList({
					page: this.page,
					limit: this.pageSize,
					type: this.current == 0 ? 4 : 6
				}).then(res => {
					let datas = res.data
					for (let item of datas) {
						for (let o of item.cartInfo) {
							o.bdInfo = {}
							if (o.bd_value[0] == '{') {
								o.bdInfo = JSON.parse(o.bd_value)
							}
						}
					}
					if (this.page == 1) {
						this.orderList = res.data
					} else {
						this.orderList = [...this.orderList, ...res.data]
					}
					if (res.data.length < this.pageSize) {
						this.status = 'nomore'
					} else {
						this.status = 'loadmore'
					}
					uni.hideLoading()
				})
			},
			gourls() {
				if (this.current == 0) return
				this.$gourl('/mallPage/afterSales/salesDetails')
			},
			change(index) {
				this.current = index;
				this.page = 0
				this.orderList = []
				this.getData()
			},
		}
	}
</script>

<style scoped lang="scss">
	.nolist {
		height: 50vh;
		width: 100vw;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.btns {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-top: 20rpx;

		.btn_box {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.btn {
				width: 140rpx;
				height: 58rpx;
				border-radius: 28rpx;
				font-size: 24rpx;
				border: 1rpx solid #999999;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #333;
			}

			.pay_btn {
				color: #fff;
				background: #EA3D37;
				border: 1rpx solid #EA3D37;
			}

			.success {
				border: 1rpx solid #EA3D37;
				color: #EA3D37;
			}
		}

		.count_box {
			.money {
				text {
					color: #EA3D37;
					font-weight: 500;
				}
			}

			.goods {
				color: #999999;
				font-size: 20rpx;
			}
		}
	}

	.list {
		padding: 20rpx 30rpx;
		background: #fff;
		margin-bottom: 30rpx;
		border-radius: 20rpx;

		.title {
			padding-bottom: 20rpx;
			position: relative;
			border-bottom: 1px solid #eee;
			display: flex;
			align-items: center;
			font-size: 28rpx;
			color: #333;
			justify-content: space-between;

			.status {
				color: #26ACF5;
			}
		}

		.content_con {
			padding-top: 30rpx;
			padding-bottom: 20rpx;
			border-bottom: 1px solid #eee;

			.head {
				padding: 20rpx 0;
				display: flex;
				align-items: center;
				justify-content: space-between;

				.left {
					display: flex;
					align-items: center;

					image {
						width: 50rpx;
						height: 50rpx;
						border-radius: 10rpx;
						margin-right: 20rpx;
					}
				}
			}

			.small_info {
				margin-top: 20rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				image {
					width: 130rpx;
					height: 130rpx;
					border-radius: 10rpx;
				}

				.price_box {
					display: flex;
					align-items: center;
					justify-content: center;
					text-align: right;

					.big_price {
						font-size: 32rpx;

						text {
							font-size: 24rpx;
						}
					}

					.small_price {
						font-size: 28rpx;
						color: #666;
						text-decoration: line-through;

						text {
							font-size: 16rpx;
						}
					}
				}

				.infos {
					flex: 1;
					padding-left: 20rpx;
					width: 596rpx;
					line-height: 1.8;

					.name {
						font-size: 24rpx;
						text-overflow: -o-ellipsis-lastline;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-line-clamp: 1;
						-webkit-box-orient: vertical;
					}

					.sku {
						font-size: 20rpx;
						color: #666;
					}
				}

				.num_a_wd {
					display: flex;
					align-items: center;
					justify-content: flex-start;
					font-size: 24rpx;

					.wd_box {
						display: flex;
						margin-left: 20rpx;
						align-items: center;
						justify-content: space-between;
						background: #F6F6F7;
						height: 32rpx;
						border-radius: 6rpx;
						font-size: 20rpx;
						padding: 0 14rpx;

						.ice {
							color: #26ACF5;
						}
					}
				}
			}

		}
	}

	.container {
		min-height: 100vh;
		background: #f8f8f8;
		padding-bottom: 30rpx;
	}

	.tab_box {
		width: 750rpx;
		height: 100rpx;
		z-index: 999;
		position: sticky;
		left: 0;
		top: 0;
		background: #FFFFFF;
		border-bottom: 1px solid #f0f0f0;
	}
</style>